<?php
namespace Crm\Domain;

use Crm\Common\MetaData as MetaData;

class Total
{
    protected $session; //当前用信息[上下文]

    /**
     * pdo连接。
     *
     * @var object
     * @access pdo
     */
    public $pdo;

    public $metaData;
    public $baseCode;
    public $city_code;
    public $provinceCode;

    public function __construct()
    {
        $this->pdo = \PhalApi\DI()->pdo;
        $this->baseCode = (object)\PhalApi\DI()->config->get('basecode');
        $this->province_code = \PhalApi\DI()->config->get('app.provinceCode');//省
        $this->city_code = \PhalApi\DI()->config->get('app.cityCode');//城市

        $this->metaData = new MetaData();
    }

    /* 今日个人统计 */
    public function todayPerson($user){
        //todayAddEsfNum:0,     //今日新增房源
        //todayAddCustomerNum:0,//今日新增客源
        //todayMoveEsfNum: 0,   //今日转交房源
        //warnEsfNum:0,         //7天未跟进
        //dangerEsfNum:0,       //15天未跟进
        $today_start = strtotime(date('Y-m-d 00:00:00',time())) ;
        $today_end   = strtotime(date('Y-m-d 23:59:59',time()));

        $sql = "select count(*) as num from fc_esf as a where a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增房源
        $result['todayAddEsfNum'] = $this->pdo->getRow($sql);
        $sql = "select count(*) as num from fc_esf as a where a.house_type=1 and a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增房源
        $result['todayAddEsfSaleNum'] = $this->pdo->getRow($sql);
        $sql = "select count(*) as num from fc_esf as a where a.house_type=2 and a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增房源
        $result['todayAddEsfRentNum'] = $this->pdo->getRow($sql);


        $sql =" select count(*) as num from crm_customer as a where a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增客源
        $result['todayAddCustomerNum'] = $this->pdo->getRow($sql);//今日新增客源
        $sql =" select count(*) as num from crm_customer as a where a.require_type=1010201 and a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增客源
        $result['todayAddCustomerBuyNum'] = $this->pdo->getRow($sql);//今日新增购买客源
        $sql =" select count(*) as num from crm_customer as a where a.require_type=1010202 and a.create_date >= ".$today_start." and a.create_date <= ".$today_end;//今日新增客源
        $result['todayAddCustomerRentNum'] = $this->pdo->getRow($sql);//今日求租购买客源


        $warn_outdate = time()-(86400*$this->baseCode->esf['warn_outdays']);
        $danger_outdate = time()-(86400*$this->baseCode->esf['danger_outdays']);
        $sql = "select count(*) as num from fc_esf as a where a.owner_uid=".$user['user_id']." and (a.log_date <= ".$warn_outdate." and a.log_date >= ".$danger_outdate.")";//7日未跟进[我的]
        $result['warnEsfNum'] = $this->pdo->getRow($sql);
        $sql = "select count(*) as num from fc_esf as a where a.owner_uid=".$user['user_id']." and a.log_date <= ".$danger_outdate;//15日未跟进[我的]
        $result['dangerEsfNum'] = $this->pdo->getRow($sql);
        return $result;
    }


}

